const { prisma } = require('../config/prisma');

async function createChatPackages() {
  try {
    console.log('开始创建聊天消息套餐...');

    // 创建聊天消息套餐
    const chatPackages = [
      {
        title: '聊天体验包',
        description: '适合轻度聊天用户，包含10条消息',
        price: 1.00,
        credits_amount: 10,
        package_type: 'chat_message',
        is_active: true,
        sort_order: 1
      },
      {
        title: '聊天标准包',
        description: '适合日常聊天用户，包含50条消息',
        price: 5.00,
        credits_amount: 50,
        package_type: 'chat_message',
        is_active: true,
        sort_order: 2
      },
      {
        title: '聊天畅聊包',
        description: '适合活跃聊天用户，包含200条消息',
        price: 15.00,
        credits_amount: 200,
        package_type: 'chat_message',
        is_active: true,
        sort_order: 3
      },
      {
        title: '聊天无限包',
        description: '适合重度聊天用户，包含1000条消息',
        price: 50.00,
        credits_amount: 1000,
        package_type: 'chat_message',
        is_active: true,
        sort_order: 4
      }
    ];

    for (const packageData of chatPackages) {
      const existingPackage = await prisma.packages.findFirst({
        where: {
          title: packageData.title,
          package_type: 'chat_message'
        }
      });

      if (!existingPackage) {
        const createdPackage = await prisma.packages.create({
          data: packageData
        });
        console.log(`创建套餐: ${createdPackage.title} - ${createdPackage.credits_amount}条消息 - ¥${createdPackage.price}`);
      } else {
        console.log(`套餐已存在: ${packageData.title}`);
      }
    }

    console.log('聊天消息套餐创建完成！');
  } catch (error) {
    console.error('创建聊天消息套餐失败:', error);
  } finally {
    await prisma.$disconnect();
  }
}

// 如果直接运行此脚本
if (require.main === module) {
  createChatPackages();
}

module.exports = createChatPackages;
